package com.jmb.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jmb.api.model.entity.Permission;
import com.jmb.api.model.entity.PermissionRole;
import com.jmb.api.model.entity.Role;
import com.jmb.api.service.PermissionRoleService;
import com.jmb.api.mapper.PermissionRoleMapper;
import com.jmb.api.vo.permissionRole.PermissionRoleInfoVo;
import com.jmb.api.vo.permissionRole.PermissionRoleVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author jinbo
* @description 针对表【permission_role】的数据库操作Service实现
* @createDate 2025-04-08 13:53:56
*/
@Service
public class PermissionRoleServiceImpl extends ServiceImpl<PermissionRoleMapper, PermissionRole>
    implements PermissionRoleService{

    @Autowired
    private PermissionRoleMapper permissionRoleMapper;
    @Override
    public List<PermissionRoleInfoVo> getListByRoleId(Integer roleId) {
        return permissionRoleMapper.getListByRoleId(roleId);
    }

    @Override
    public void savePermissionRole(PermissionRoleVo permissionRoleVo) {
        PermissionRole permissionRole = new PermissionRole();
        BeanUtils.copyProperties(permissionRoleVo,permissionRole);
        this.save(permissionRole);

    }

    @Override
    public void removePermissionRole(PermissionRoleVo permissionRoleVo) {
        LambdaQueryWrapper<PermissionRole> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PermissionRole::getPermissionId,permissionRoleVo.getPermissionId());
        queryWrapper.eq(PermissionRole::getRoleId,permissionRoleVo.getRoleId());
        this.remove(queryWrapper);
    }
}




